package com.prolestar.publicsentiment.mapper;


import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.prolestar.publicsentiment.domain.ApportionPubilcsentiment;
import com.prolestar.publicsentiment.domain.PsDealLog;
import com.prolestar.publicsentiment.domain.PsPublicsentiment;
import com.prolestar.publicsentiment.domain.StrategyByInvolved;
import com.prolestar.statistics.domain.BasicPublicsent;
import com.prolestar.statistics.res.IndustryStatisticsRes;
import com.prolestar.statistics.res.TerritorialStatisticsOfPublicOpinionRes;
import com.prolestar.statistics.res.YuqingDealData;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 舆情处置Mapper接口
 * 
 * @author ruoyi
 * @date 2022-11-11
 */
@Mapper
public interface PsPublicsentimentMapper 
{
    /**
     * 查询舆情处置
     * 
     * @param id 舆情处置主键
     * @return 舆情处置
     */
    public PsPublicsentiment selectPsPublicsentimentById(Long id);

    /**
     * 查询舆情处置列表
     * 
     * @param psPublicsentiment 舆情处置
     * @return 舆情处置集合
     */
    public List<PsPublicsentiment> selectPsPublicsentimentList(PsPublicsentiment psPublicsentiment);

    /**
     * 新增舆情处置
     * 
     * @param psPublicsentiment 舆情处置
     * @return 结果
     */
    public int insertPsPublicsentiment(PsPublicsentiment psPublicsentiment);

    /**
     * 修改舆情处置
     * 
     * @param psPublicsentiment 舆情处置
     * @return 结果
     */
    public int updatePsPublicsentiment(PsPublicsentiment psPublicsentiment);

    /**
     * 删除舆情处置
     * 
     * @param id 舆情处置主键
     * @return 结果
     */
    public int deletePsPublicsentimentById(Long id);

    /**
     * 批量删除舆情处置
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deletePsPublicsentimentByIds(Long[] ids);

    void addApportion(ApportionPubilcsentiment pubilcsentiment);

    List<PsPublicsentiment> selectPsPublicsentimentUserList(PsPublicsentiment psPublicsentiment);

    void insertPsDealLog(PsDealLog psDealLog);

    /**
     * 根据时间范围查询数据
     * @param
     * @param
     * @return
     */
    @Select("select a.id, a.ps_status as psStatus,a.create_time as createTime from ps_publicsentiment a where YEAR(a.create_time)=YEAR(NOW()) and a.is_delete != 1  ")
    List<BasicPublicsent> selectByCreateTimeRange();

    @Select("select count(a.id) from ps_publicsentiment a where to_days(a.release_time) = to_days(#{time}) and a.is_delete != 1" )
    long selectCountByTime(@Param(value = "time") Date time);

    @Select("select count(a.id) as total ,a.release_area as releaseArea,(select b.dict_label from sys_dict_data b where b.dict_value=a.release_area and b.dict_type='ps_possession') as releaseAreaName from ps_publicsentiment a where a.is_delete != 1  group by a.release_area")
    List<TerritorialStatisticsOfPublicOpinionRes> selectreleaseArea();

    @Select("select count(a.id) as total ,a.issues_involved as issuesInvolved,(select b.dict_label from sys_dict_data b where b.dict_value=a.issues_involved and b.dict_type='ps_industry') as issuesInvolvedName from ps_publicsentiment a where a.is_delete != 1  group by a.issues_involved")
    List<IndustryStatisticsRes> selectIndustry();

    @Select("SELECT\r\n" + 
    		"	a.id as id,\r\n" + 
    		"	a.ps_id as psId,\r\n" + 
    		"	a.distri_unit_id as distriUnitId,(\r\n" + 
    		"	SELECT\r\n" + 
    		"		c.dept_name \r\n" + 
    		"	FROM\r\n" + 
    		"		sys_dept c \r\n" + 
    		"	WHERE\r\n" + 
    		"		c.dept_id = a.distri_unit_id \r\n" + 
    		"	) AS unitName,\r\n" + 
    		"	a.STATUS as status,\r\n" + 
    		"	a.sign as sign,\r\n" + 
    		"	a.readStatus as readStatus \r\n" + 
    		"FROM\r\n" + 
    		"	ps_distribution_task a\r\n" + 
    		"	LEFT JOIN ps_publicsentiment b ON a.ps_id = b.id \r\n" + 
    		"WHERE\r\n" + 
    		"	b.create_time > #{startTime} \r\n" + 
    		"	AND b.create_time < #{endTime} \r\n" +
            "   AND b.is_delete != 1"
        )
    List<YuqingDealData> selectFindByTime(@Param(value = "startTime") Date startTime, @Param(value = "endTime") Date endTime);

    List<PsPublicsentiment> selectAll();

    void updateApportionSign(ApportionPubilcsentiment apportionPubilcsentiment);

    void updatePsStatusById(Long id);

    List<StrategyByInvolved> StrategyByInvolved(StrategyByInvolved strategyByInvolved);

    List<ApportionPubilcsentiment> taskList(ApportionPubilcsentiment apportionPubilcsentiment);

    void updateApportionRead(ApportionPubilcsentiment apportionPubilcsentiment);

    void updateApportion(ApportionPubilcsentiment apportionPubilcsentiment);

    void updateApportionsendBack(ApportionPubilcsentiment apportionPubilcsentiment);

    void updatePsStatus(PsPublicsentiment psPublicsentiment);

    List<PsDealLog> selectOperation(PsDealLog psDealLog);

    PsPublicsentiment selectPsPublicsentimentUserById(Long taskId);

}
